import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'umi';
import { Line } from '@ant-design/plots';

const RankLineChart = (props: any) => {
  const [data, setData] = useState([]);
  const getAllList = () => {
    if (props.dispatch) {
      props.dispatch({
        //路径：model的namespace+effects函数名
        type: 'Model_StudentAnalysisStudentModel/getStudentRankAnalysisEffects',
        payload: {
          data: JSON.parse(props.user.currrentuser).account,
          callback: (value: any) => {
            setData(value);
          },
        },
      });
    }
  };
  useEffect(() => {
    if (props.user.currrentuser.length != 0) {
      console.log(JSON.parse(props.user.currrentuser));
      getAllList();
    }
  }, [props]);
  const config = {
    data,
    xField: 'year',
    yField: 'value',
    seriesField: 'category',
    smooth: true,
  };

  return <Line {...config} />;
};

export default connect(({ Model_StudentAnalysisStudentModel, user }: any) => ({
  ...Model_StudentAnalysisStudentModel,
  user,
}))(RankLineChart);
